<?php

if (!defined('_PAGE_'))
    include _FLEP_LIB_DIR_.'/page.inc';

if(isset($_GET['curso']) && $_GET['curso'] != "") {
  include 'pages/detalle_curso.inc';
} else {
  include 'pages/curso.inc';
}

$css = array('main.css', 'table.css', 'title_menu.css', 'title_msg.css', 'table_info.css', 'aside.css', 'detalle_curso.css', 'lightbox.css');
$javascript = array('jquery-1.9.1.js', 'jquery-ui.js', 'common.js', 'ajax.js', 'search.js', 'request.js', 'lightbox.js', 'entrada.js', 'delete.js', 'add_curso.js', 'detalle_curso.js');

flep_structure($entradas, 'entrada');
$structure['entradas'] = &$entradas;

function include_page($structure){
$user = &$_SESSION['user'];
$entradas = &$structure['entradas'];
?>
    <div class="aside">
      <br>
        <a href="main.php?page=entrada">Entradas</a>
        <br>
        <br>
        <?php if(flep_get($user, 'administrador') === '1') { ?>
          <label onclick="flep_add_entrada('');"><img src="img/add_entrada.png" />&nbsp;Nueva Entrada</label>
          <br>
        <?php }?>
        <?php
            $year = date('Y');
            $entradas['where'] = array(sprintf('`fecha_inicio` BETWEEN \'%1$s-1-1\' AND \'%1$s-12-31\'', $year));
            $hide_all = false;
            while(flep_search_all($entradas)){
              ?>
                <br><label onclick="flep_show_menu('y<?php echo $year;?>')">
                  <img  id="imgy<?php echo $year;?>" src="img/<?php echo ($hide_all? 'plus':'minus');?>.png" />
                  <b><?php echo $year;?></b>
                </label>
                <br>
                <div id="y<?php echo $year; echo ($hide_all? '" style="display:none;':'');?>">
                <?php
                flep_structure($programas, 'programa');
                flep_search_all($programas);
                foreach($programas['data'] as $programa ) {
                ?>
                  <label style="padding-left: 10px;" onclick="flep_show_menu('y<?php echo $year.$programa['programa'];?>')">
                  <img id="imgy<?php echo $year.$programa['programa'];?>" src="img/<?php echo ($hide_all? 'plus':'minus');?>.png" />
                  <b><?php echo $programa['programa'];?></b>
                  </label>
                  <br>
                  <div id="y<?php echo $year.$programa['programa']; echo ($hide_all? '" style="display:none;':'');?>" >
                  <br><?php
                    foreach($entradas['data'] as $entrada ) {
                      if($entrada['programa_id'] === $programa['id']){
                      ?>
                      <label style="padding-left: 20px;" onclick="flep_show_entrada('<?php echo flep_encode($entrada['id']);?>');">
                      <b>#<?php echo $entrada['entrada'];?></b>&nbsp;<?php
                      echo str_replace('-', '/', str_replace($year.'-', '', $entrada['fecha_inicio'])); ?>&nbsp;-&nbsp;<?php
                      echo str_replace('-', '/', str_replace($year.'-', '', $entrada['fecha_cierre'])); ?></label><br>
                      <?php
                    }
                  }
                  echo '<br></div>';
                }
              $hide_all = true;
              echo '</div>';
              $entradas['where'] = array(sprintf('`fecha_inicio` BETWEEN \'%1$s-1-1\' AND \'%1$s-12-31\'', --$year));
            }
        ?>
    </div>
    <div class="bside" id="div_curso">
      <?php 
          include_curso($structure);
      ?>
  </div>
<?php
}

?>
